﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入数组：");
            int counter = 0;
            int[] record = new int[100];
            var next = Console.ReadLine();
            while (!string.IsNullOrWhiteSpace(next))
            {
                if (next != "")
                {
                    try
                    {
                        int num = Int32.Parse(next);
                        record[counter] = num;
                    }
                    catch
                    {
                        Console.WriteLine("输入错误，请重新输入：");
                        next = Console.ReadLine();
                        continue;
                    }
                    counter++;
                }
                next = Console.ReadLine();
            }
            if (counter == 0)
            {
                Console.WriteLine("数组为空");
            }
            else { 
                int[] data = new int[counter];
                Array.Copy(record, 0, data, 0, counter);
                int max, min, aver, and;
                Program.ProcessingArray(data, out max, out min, out aver, out and);
                Console.WriteLine("最大值是：" + max);
                Console.WriteLine("最小值是：" + min);
                Console.WriteLine("平均值是：" + aver);
                Console.WriteLine("数组元素和是：" + and);
            }
        }
        public static void ProcessingArray(int[]data,out int max,out int min,out int ave,out int and)
        {
            max = data[0];
            min = data[0];
            and = data[0];
            for(int i = 1; i < data.Length; i++)
            {
                max = max > data[i] ? max : data[i];
                min = min < data[i] ? min : data[i];
                and += data[i];
            }
            ave = and / data.Length;
        }
    }
}
